package face.pay.api.payter;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import face.pay.api.payter.channel.AbstractChannel;
import face.pay.util.ResultMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;

/**
 * 收款设备
 */
@Slf4j
public abstract class AbstractPayTerminal {

    /**
     * 扫码支付
     * @return
     */
    public  ResultMessage facePay(String json){

        log.info("刷脸支付");
        try{

            if(StringUtils.isBlank(json)){
                return ResultMessage.createFail("请求数据错误");
            }
            JSONObject jsonObject = JSON.parseObject(json);

            AbstractChannel abstractChannel  =  this.channel(jsonObject);

            log.info("渠道选择");
            return  abstractChannel.facePay(jsonObject);
        }catch (Exception e){
           log.error("facePay error",e);
        }

        return ResultMessage.createFail("支付失败");

    }


    /**
     * 扫码支付
     * @return
     */
    public  ResultMessage qrPay(String json){

        JSONObject jsonObject = JSON.parseObject(json);

        AbstractChannel abstractChannel  =  this.channel(jsonObject);

        return  abstractChannel.qrPay(jsonObject);

    }


    public  ResultMessage jsPay(String json){

        JSONObject jsonObject = JSON.parseObject(json);

        AbstractChannel abstractChannel  =  this.channel(jsonObject);

        return  abstractChannel.jsPay(jsonObject);

    }

    /**
     * 支付结果检测
     * @param json
     * @return
     */
    public abstract ResultMessage payResult(String json);


    public abstract AbstractChannel channel(JSONObject json);



}
